/**
 * @author Linrui
 * @since 2011-04-30
 * 负责首页的数据加载
 */
package com.qeado.index.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.qeado.news.service.NewsService;
import com.qeado.product.model.Product;
import com.qeado.product.service.ProductService;
import com.qeado.sort.service.SortService;
import com.qeado.util.PageHelper;
@Scope("session")
@Controller
public class IndexAction extends ActionSupport {

	@Autowired
	private NewsService newsService;
	@Autowired
	private ProductService productService;
	
	private PageHelper newInfo; // 最新发布的资讯
	private PageHelper newsColleageInfo; // 最新发布的校园类信息
	private PageHelper newSell; // 最新发布的出售信息
	private PageHelper newBuy; // 最新发布的采购信息
	private Map<String, PageHelper> newsProd; // 每个类别最新发布的信息
	
	public Map<String, PageHelper> getNewsProd() {
		return newsProd;
	}

	public void setNewsProd(Map<String, PageHelper> newsProd) {
		this.newsProd = newsProd;
	}

	public PageHelper getNewSell() {
		return newSell;
	}

	public void setNewSell(PageHelper newSell) {
		this.newSell = newSell;
	}

	public PageHelper getNewBuy() {
		return newBuy;
	}

	public void setNewBuy(PageHelper newBuy) {
		this.newBuy = newBuy;
	}

	public PageHelper getNewsColleageInfo() {
		return newsColleageInfo;
	}

	public void setNewsColleageInfo(PageHelper newsColleageInfo) {
		this.newsColleageInfo = newsColleageInfo;
	}

	public PageHelper getNewInfo() {
		return newInfo;
	}

	public void setNewInfo(PageHelper newInfo) {
		this.newInfo = newInfo;
	}

	@Override
	public String execute() throws Exception {
		/* 加载最新资讯 */
		newInfo = newsService.listByPage(1);
		/* 加载最新发布的出售物品*/
		newSell = productService.listAll(1, 6, "create_date", "desc", "1"); 
		/* 加载最新发布的采购物品*/
		newBuy = productService.listAll(1, 6, "create_date", "desc", "2"); 
		/* 加载最新的校园资讯*/
		newsColleageInfo = newsService.listByTypeLike(1, 10, "SH", "create_date", "desc");
		// 如果每个类别的最新发布的产品没有加载，则进行加载

//		if( null == this.newsProd) {
			newsProd = new HashMap<String , PageHelper>();
			newsProd.put("ZA", productService.listBySortLike(1, 4, "ZA", "create_date", "desc", null));
			newsProd.put("ZB", productService.listBySortLike(1, 4, "ZB", "create_date", "desc", null));
			newsProd.put("ZC", productService.listBySortLike(1, 4, "ZC", "create_date", "desc", null));
			newsProd.put("ZD", productService.listBySortLike(1, 4, "ZD", "create_date", "desc", null));
			newsProd.put("ZE", productService.listBySortLike(1, 4, "ZE", "create_date", "desc", null));
			newsProd.put("ZF", productService.listBySortLike(1, 4, "ZF", "create_date", "desc", null));
			newsProd.put("ZG", productService.listBySortLike(1, 4, "ZG", "create_date", "desc", null));
			newsProd.put("ZH", productService.listBySortLike(1, 4, "ZH", "create_date", "desc", null));
//		}	
		return super.execute();
	}
		
	
}
